package com.viators.model;

import java.sql.*;
import javax.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author Valentín Palomino Marco Antonio
 * @version 1.0 19/11/2010
 */
public class Datos {
    public static Connection obtenerConexion(){
        Connection conexion = null;
        try{
            Context contexto = new InitialContext();
            DataSource origenDatos = (DataSource)contexto.lookup("java:comp/env/jdbc/myDatasource");
            conexion = origenDatos.getConnection();
        }catch(Exception ex){
            System.out.println("-----Error de Conexion: " + ex.getMessage());
            ex.printStackTrace();
        }
        return conexion;
    }
    public static void cerrarConexion(Connection conexion){
        try{
            if(conexion != null) conexion.close();
        }catch(Exception ex){
            System.out.println("-----Error al cerrar conexion: " + ex.getMessage());
            ex.printStackTrace();
        }
    }
}